﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class addclass : Form
    {
        static SqlConnection con = new SqlConnection("server=.;database=C;pwd=123456;uid=sa;");
        static SqlCommand com;

        public addclass()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                com = new SqlCommand("insert into Class values(@id,@name)", con);
                com.Parameters.AddWithValue("@id", Int32.Parse(textBox2.Text));
                com.Parameters.AddWithValue("@name", textBox1.Text);
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
            }
            catch(Exception a)
            {
                MessageBox.Show(a.Message+"  请输入正确格式！");
            }
            MessageBox.Show("添加成功!");
            Form1.bs = 1;
            con.Close();
            this.Close();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
